home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
RpcalcInpu
< prev
next >
Wrap
Text File
|
1995-06-28
|
2KB
|
40 lines
Rpcalc Input
Previous: <Rpcalc Rules=>RpcalcRulf> * Next: <Rpcalc Line=>RpcalcLine> * Up: <Rpcalc Rules=>RpcalcRulf>
#Wrap on
{fH5}Explanation of {fCode}input{f}{f}
Consider the definition of {fCode}input{f}:
#Wrap off
#fCode
input: \/\* empty \*\/
| input line
;
#f
#Wrap on
This definition reads as follows: ``A complete input is either an empty
string, or a complete input followed by an input line''. Notice that
``complete input'' is defined in terms of itself. This definition is said
to be {fUnderline}left recursive{f} since {fCode}input{f} appears always as the
leftmost symbol in the sequence. \*Note <Recursion=>Recursion>: Recursive Rules.
The first alternative is empty because there are no symbols between the
colon and the first {fEmphasis}|{f}; this means that {fCode}input{f} can match an
empty string of input (no tokens). We write the rules this way because it
is legitimate to type {fCode}Ctrl-d{f} right after you start the calculator.
It's conventional to put an empty alternative first and write the comment
{fEmphasis}\/\* empty \*\/{f} in it.
The second alternate rule ({fCode}input line{f}) handles all nontrivial input.
It means, ``After reading any number of lines, read one more line if
possible.'' The left recursion makes this rule into a loop. Since the
first alternative matches empty input, the loop can be executed zero or
more times.
The parser function {fCode}yyparse{f} continues to process input until a
grammatical error is seen or the lexical analyzer says there are no more
input tokens; we will arrange for the latter to happen at end of file.